package com.example.blogsystem_ssm.controller;

import com.example.blogsystem_ssm.model.Blog;
import com.example.blogsystem_ssm.model.User;
import com.example.blogsystem_ssm.service.AuthorInfoService;
import com.example.blogsystem_ssm.tools.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class AuthorInfoController {
    @Autowired
    AuthorInfoService service;

    @RequestMapping(value = "/authorInfo")
    public Blog getBlog(@RequestParam Integer blogId){
        Blog blog =  service.getBlog(blogId);
        return blog;
    }
    @RequestMapping(value ="/authorInfo2")
    public ResponseBodyMessage<User> getUser(@RequestParam Integer blogId){
        Blog blog =  service.getBlog(blogId);
        //根据 blog 对象，查询到用户对象
        User author = service.selectById(blog.getUserId());
        return new ResponseBodyMessage<>(0,"找到了",author);
    }
}
